import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:xiandou/Common.dart';
import 'package:xiandou/Request/DioManager.dart';
import 'package:xiandou/Request/NWApi.dart';
import 'package:xiandou/Request/NWMethod.dart';

class WithdrawalRecordController extends StatefulWidget {
  @override
  State<StatefulWidget> createState() =>  WithdrawalRecordControllerState();
}

class WithdrawalRecordControllerState extends State<WithdrawalRecordController> {

  String sum ='0';
  List withdrawListData =[];

  String indexToStatusString(int status) {
    switch(status) {
      case 0: {
        return '处理中';
      }
      break;

      case 1: {
        return '提现成功';
      }
      break;

      case -1: {
        return '提现被拒绝';
      }
      break;

      default: {
        return '处理中';
      }
      break;
    }
  }

  void getCoinWithDrawListData (){
    DioManager().request(NWMethod.GET, NWApi.coinWithDrawListApi,params: null,success: (data){
      setState(() {
        withdrawListData =data['list'];
        sum = data['totalAmount'].toString();
      });
    },error: (error){
      Fluttertoast.showToast(msg: error.message);
    });
  }

  @override
  void initState() {
    // TODO: implement initState
    getCoinWithDrawListData();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: CupertinoNavigationBar(
          backgroundColor: Colors.white,
          middle: const Text('提现记录'),
        ),
        body: Container(
          child: Column(
            children: <Widget>[
              Container(
                padding: const EdgeInsets.only(left: 18),
                alignment: Alignment.centerLeft,
                height: 48.5,
                child: Row(
                  children: <Widget>[
                    Text('本月:  '),
                    Text('¥' +sum,style: TextStyle(color: Common.blackColor,fontSize: 17,fontWeight: FontWeight.bold),),
                  ],
                )
              ),
              Expanded(
                child: Container(
                    color: Colors.white,
                    child: ListView.builder(itemBuilder: (BuildContext buildContext,int index){
                      if(withdrawListData.length == 0) {
                        return Container(
                          padding: const EdgeInsets.only(top: 50),
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: <Widget>[
                              Image(image: AssetImage('assets/d_empty.png'),width: 200,height: 200,),
                              SizedBox(height: 30,),
                              Text('暂无内容',style: TextStyle(color: Common.darkColor,fontSize: 14),),
                            ],
                          ),
                        );
                      }
                      int paymentType = withdrawListData[index]['paymentType'];
                      return Container(
                        height: 80,
                        padding: const EdgeInsets.only(left: 18,right: 12),
                        child: Row(
//                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: <Widget>[
                            Image(image: AssetImage('assets/d_ali.png'),width: 28,height: 28,),
                            SizedBox(width: 12,),
                            Expanded(
                              child: Column(
                                mainAxisAlignment: MainAxisAlignment.center,
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: <Widget>[
                                  Text(paymentType == 1 ? '提现到微信' : '提现到支付宝',style: TextStyle(color: Colors.black),),
                                  SizedBox(height: 5,),
                                  Text(withdrawListData[index]['createTime'],style: TextStyle(color: Common.grayColor),)
                                ],
                              ),
                            ),
                            Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: <Widget>[
                                Text(withdrawListData[index]['amount'].toString(),style: TextStyle(color: Common.xdOrangeColor,fontSize: 17,fontWeight: FontWeight.bold),),
                                Text(indexToStatusString(withdrawListData[index]['status']),style: TextStyle(color: Common.darkColor),),
                              ],
                            )
                          ],
                        ),
                      );
                    },itemCount: withdrawListData.length == 0 ? 1 : withdrawListData.length,)
                )
              )
            ],
          ),
        )
    );
  }
}